package com.eightywork.life.service;

import android.util.Log;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

public class BaseService {
	  public static final String DOMAIN = "http://www.lifeq.com.cn/";

	//  public static final String DOMAIN = "http://test.lifeq.com.cn/";
	/**
	 * jsonarray 转成 字符串用,分隔
	 * 
	 * @param json
	 * @return
	 */
	public static String JsonArrayToStrings(JsonArray array) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < array.size(); i++) {
			sb.append(array.get(i).getAsJsonObject().get("big").getAsString());
			if (i < array.size() - 1) {
				sb.append(",");
			}
		}
		return sb.toString();
	}

	/**
	 * jsonarray 转成 字符串用,分隔
	 * 
	 * @param json
	 * @return
	 */
	public static String JsonArrayToStringsSmall(JsonArray array) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < array.size(); i++) {
			sb.append(array.get(i).getAsJsonObject().get("small").getAsString());
			if (i < array.size() - 1) {
				sb.append(",");
			}
		}
		return sb.toString();
	}

	/**
	 * 根据用户id增加赞内容
	 * 
	 * @param sourceArray
	 * @return
	 */
	public static JsonArray makeShowgood(JsonArray sourceArray) {
		JsonArray array = new JsonArray();
		JsonObject object = new JsonObject();
		object.addProperty("name", CacheService.getSpace().getName());
		array.add(object);
		for (int i = 0; i < sourceArray.size(); i++) {
			array.add(sourceArray.get(i).getAsJsonObject());
		}
		return array;
	}

	/**
	 * 根据用户id删除赞内容
	 * 
	 * @param sourceArray
	 * @return
	 */
	public static JsonArray removeShowgood(JsonArray sourceArray) {
		JsonArray array = new JsonArray();
		for (int i = 0; i < sourceArray.size(); i++) {
			Log.d("1", sourceArray.get(i).getAsJsonObject().get("uid") + CacheService.getSpace().getUid());
			if (!sourceArray.get(i).getAsJsonObject().get("uid")
					.equals(CacheService.getSpace().getName())) {
				array.add(sourceArray.get(i).getAsJsonObject());
			}
		}
		return array;
	}
}
